 /*///////////////////////////////////////////////////////////////////////////////
-- Author:      liuhx
-- Created:     Wed Nov 28 11:36:25 CST 2018
-- Description:	    
-- If you have any question,please email to liuhx@gentlesoft.com.cn 
////////////////////////////////////////////////////////////////////////////////*/
package com.ctsi.question.service;

 import com.ctsi.commons.util.UtilValidate;
 import com.ctsi.commons.util.id.UUIDGenerator;
 import com.ctsi.commons.util.response.Page;
 import com.ctsi.framework.mybatis.support.MybatisGenericDao;
 import com.ctsi.question.entity.Question;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;

 import java.util.Map;


/**
 * Question Service 类
 * @author   liuhx
 * @description  Question
 * @created	 Wed Nov 28 11:36:25 CST 2018
 */

@Service
public class QuestionService {
	private static final Logger logger=LoggerFactory.getLogger(QuestionService.class);
	@Autowired
	private MybatisGenericDao dao;
	/*
	* 查询当前用户所回答过的问题
	* */
    public Page<Question> selectQuLibByLoginId(Map<String,Object> param , int start , int pageSize){
        logger.debug("selectQuLibByLoginId {}",param);
        if(pageSize<0||pageSize>2000)
            pageSize=Page.DEFAULT_PAGE_SIZE;
        if(start!=-1)
            return dao.queryPage(Question.class.getName()+".selectQuLibByLoginId", param, start, pageSize);
        else{
            throw new RuntimeException("参数不正确 !!");
        }
    }
	/**
	 * 添加
	 */
	public int insertQuestion(Question question){
		if(UtilValidate.isEmpty(question.getId()))
			question.setId(UUIDGenerator.getId());
		logger.debug("insert {}",question);
		return dao.insert(Question.class.getName()+".insert",question);
	}
	/**
	 * 动态更新
	 */	
	public int updateQuestionById(Question question){
		logger.debug("updateQuestionById {}",question);
		return dao.update(Question.class.getName()+".updateQuestionById", question);
	}

	/*
	* 更新浏览数量
	* */
	public int updateLiuLanNumById(Question question){
		logger.debug("updateLiuLanNumById {}",question);
		return dao.update(Question.class.getName()+".updateLiuLanNumById",question);
	}

	/*
	* 根据id查询问题详情
	* */
	public Question selectQuestionById(String id){
		if(UtilValidate.isEmpty(id))
			return null;
		logger.debug("selectQuestionById {}",id);
		return (Question)dao.queryForObject(Question.class.getName()+".selectQuestionById", id);
	}

	/**
	 * 删除Question对象（is_default=1）
	 */
	public int deleteQuestionById(Question question){
		logger.debug("deleteQuestionById {}",question);
		return dao.update(Question.class.getName()+".deleteQuestionById", question);
	}

	/** 
	 * 多条件查询结果 
	 */
	public Page<Question> selectMulitCondition(Map<String,Object> param , int start , int pageSize){
		logger.debug("selectMulitCondition {}",param);
		if(pageSize<0||pageSize>2000)
			pageSize=Page.DEFAULT_PAGE_SIZE;
		if(start!=-1)
			return dao.queryPage(Question.class.getName()+".selectMulitCondition", param, start, pageSize);
		else{
			throw new RuntimeException("参数不正确 !!");
		}
	}
	/**
	 * 当前登陆用户所提问题列表
	 */
	public Page<Question> queryQuestionListByUserId(Map<String,Object> param , int start , int pageSize){
		logger.debug("queryQuestionListByUserId {}",param);
		if(pageSize<0||pageSize>2000)
			pageSize=Page.DEFAULT_PAGE_SIZE;
		if(start!=-1)
			return dao.queryPage(Question.class.getName()+".queryQuestionListByUserId", param, start, pageSize);
		else{
			throw new RuntimeException("参数不正确 !!");
		}
	}
	/*
	* 浏览量更新（每次点击详情浏览数量加1）
	* */

}
